// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PRIOR_RESULT_OML_O35 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("43 PATIENT_PRIOR",43)]
  	    [HL7Field(HL7Version.v25, 43, HL7Repeat.False, HL7Required.False,"PATIENT_PRIOR_OML_O35")]
	    public PATIENT_PRIOR_OML_O35 PATIENT_PRIOR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("47 PATIENT_VISIT_PRIOR",47)]
  	    [HL7Field(HL7Version.v25, 47, HL7Repeat.False, HL7Required.False,"PATIENT_VISIT_PRIOR_OML_O35")]
	    public PATIENT_VISIT_PRIOR_OML_O35 PATIENT_VISIT_PRIOR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("51 AL1",51)]
  	    [HL7Field(HL7Version.v25, 51, HL7Repeat.True, HL7Required.False,"AL1")]
	    public AL1[] AL1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("52 ORDER_PRIOR",52)]
  	    [HL7Field(HL7Version.v25, 52, HL7Repeat.True, HL7Required.True,"ORDER_PRIOR_OML_O35")]
	    public ORDER_PRIOR_OML_O35[] ORDER_PRIOR {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PATIENT_PRIOR = ProcessGroup<PATIENT_PRIOR_OML_O35>(availableData, options, "PATIENT_PRIOR");
			PATIENT_VISIT_PRIOR = ProcessGroup<PATIENT_VISIT_PRIOR_OML_O35>(availableData, options, "PATIENT_VISIT_PRIOR");
			AL1 = PopSegmentParseAndCheckRequiredArray<AL1>(availableData, options, "AL1");
			ORDER_PRIOR = ProcessGroupArray<ORDER_PRIOR_OML_O35>(availableData, options, "ORDER_PRIOR");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			PATIENT_PRIOR_OML_O35 testPATIENT_PRIOR_OML_O35 = new PATIENT_PRIOR_OML_O35();
			bool grpCCPATIENT_PRIOR_OML_O35 = (testPATIENT_PRIOR_OML_O35.CanConsume(availableData, options));
			if (IsRequired("PATIENT_PRIOR", options.Version) || grpCCPATIENT_PRIOR_OML_O35) {
				return grpCCPATIENT_PRIOR_OML_O35;
			}
			PATIENT_VISIT_PRIOR_OML_O35 testPATIENT_VISIT_PRIOR_OML_O35 = new PATIENT_VISIT_PRIOR_OML_O35();
			bool grpCCPATIENT_VISIT_PRIOR_OML_O35 = (testPATIENT_VISIT_PRIOR_OML_O35.CanConsume(availableData, options));
			if (IsRequired("PATIENT_VISIT_PRIOR", options.Version) || grpCCPATIENT_VISIT_PRIOR_OML_O35) {
				return grpCCPATIENT_VISIT_PRIOR_OML_O35;
			}
			bool isAL1 = availableData.StartsWith("AL1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("AL1", options.Version) || isAL1) {
				return isAL1;
			}
			ORDER_PRIOR_OML_O35 testORDER_PRIOR_OML_O35 = new ORDER_PRIOR_OML_O35();
			bool grpCCORDER_PRIOR_OML_O35 = (testORDER_PRIOR_OML_O35.CanConsume(availableData, options));
			if (IsRequired("ORDER_PRIOR", options.Version) || grpCCORDER_PRIOR_OML_O35) {
				return grpCCORDER_PRIOR_OML_O35;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PRIOR_RESULT";
			}
        }

        static PRIOR_RESULT_OML_O35() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PRIOR_RESULT_OML_O35));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PATIENT_PRIOR != null) {
			string segmentValue = PATIENT_PRIOR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PATIENT_VISIT_PRIOR != null) {
			string segmentValue = PATIENT_VISIT_PRIOR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (AL1 != null && AL1.Length > 0) {
			for (int i = 0; i < AL1.Length; i++) {
				string segmentValue = AL1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (ORDER_PRIOR != null && ORDER_PRIOR.Length > 0) {
			for (int i = 0; i < ORDER_PRIOR.Length; i++) {
				string segmentValue = ORDER_PRIOR[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

